﻿<UserControl x:Class="Hisaab.Client.Modules.Core.Management.View.ImportBankDataView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:wpf="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
             xmlns:Converters="clr-namespace:Hisaab.Client.Modules.Core.Converters"
             mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="877" >
    <UserControl.Resources>
        <Converters:AccountTypeImageConverter x:Key="accountImageConverter" UseLargeIcon="False"/>
        <Converters:TransactionTypeImageConverter x:Key="transactionImageConverter" UseLargeIcon="False"/>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="400*"/>
            <RowDefinition Height="36" />
        </Grid.RowDefinitions>
        <wpf:DataGrid ItemsSource="{Binding Transactions}" AutoGenerateColumns="False" Grid.Row="0" RowHeaderWidth="0" HeadersVisibility="Column">
            <wpf:DataGrid.Columns>
                <wpf:DataGridCheckBoxColumn Binding="{Binding Selected}" >
                    <wpf:DataGridCheckBoxColumn.HeaderTemplate>
                        <DataTemplate>
                            <CheckBox ToolTip="Select All" IsChecked="{Binding SelectAll}"  />
                        </DataTemplate>
                    </wpf:DataGridCheckBoxColumn.HeaderTemplate>
                </wpf:DataGridCheckBoxColumn>
                <wpf:DataGridTemplateColumn Header="Date" MinWidth="100" >
                    <wpf:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <wpf:DatePicker SelectedDate="{Binding Date}" SelectedDateFormat="Short" />
                        </DataTemplate>
                    </wpf:DataGridTemplateColumn.CellEditingTemplate>
                    <wpf:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Date, StringFormat=d}" />
                        </DataTemplate>
                    </wpf:DataGridTemplateColumn.CellTemplate>
                </wpf:DataGridTemplateColumn>
                <wpf:DataGridTextColumn Binding="{Binding Title}" Header="Title" />
                <wpf:DataGridTextColumn Binding="{Binding Amount}" Header="Amount" Width="100" />
                <wpf:DataGridComboBoxColumn Header="Type" SelectedValueBinding="{Binding TransactionType}" DisplayMemberPath="Value" SelectedValuePath="Key" Width="130">
                    <wpf:DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.TransactionTypes}"/>
                            <Setter Property="IsReadOnly" Value="True"/>
                        </Style>
                    </wpf:DataGridComboBoxColumn.ElementStyle>
                    <wpf:DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.TransactionTypes}"/>
                            <Setter Property="Margin" Value="0"/>
                            <Setter Property="ItemTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" >
                                            <StackPanel Orientation="Horizontal" >
                                                <Image Source="{Binding Key, Converter={StaticResource transactionImageConverter}}" Margin="3 3 10 3"/>
                                                <TextBlock Text="{Binding Value}" VerticalAlignment="Center" />
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </wpf:DataGridComboBoxColumn.EditingElementStyle>
                </wpf:DataGridComboBoxColumn>
                <wpf:DataGridComboBoxColumn Header="Account" SelectedValueBinding="{Binding Account}" DisplayMemberPath="Name" SelectedValuePath="AccountId" Width="150" >
                    <wpf:DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.Accounts}"/>
                            <Setter Property="IsReadOnly" Value="True"/>
                        </Style>
                    </wpf:DataGridComboBoxColumn.ElementStyle>
                    <wpf:DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.Accounts}"/>
                            <Setter Property="Margin" Value="0"/>
                            <Setter Property="ItemTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" >
                                            <Image Source="{Binding AccountType, Converter={StaticResource accountImageConverter}}" Margin="3 3 10 3"/>
                                            <TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </wpf:DataGridComboBoxColumn.EditingElementStyle>
                </wpf:DataGridComboBoxColumn>
                <wpf:DataGridTextColumn Binding="{Binding Details}" Header="Details" Width="200" />
            </wpf:DataGrid.Columns>
        </wpf:DataGrid>
        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Row="1">
            <Button IsDefault="True" Width="75" Command="{Binding SaveCommand}">
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="pack://application:,,,/Hisaab.Client.Common;component/Resources/Images/16/save.png" Width="16" Height="16" Margin="0 0 5 0" />
                        <TextBlock>Save</TextBlock>
                    </StackPanel>
                </Button.Content>
            </Button>
            <Button IsCancel="True" Width="75" Command="Close" >Cancel</Button>
        </StackPanel>
    </Grid>
</UserControl>